Public Class TableList
    Inherits System.MarshalByRefObject

    Private _tables As ArrayList
    Private _active As Table

    Public Sub New()
        _tables = New ArrayList
    End Sub

    Public Sub Add(ByVal tbl As Table)
        _tables.Add(tbl)
        _active = tbl
    End Sub

    Default Public ReadOnly Property Item(ByVal i As Integer) As Table
        Get
            _active = CType(_tables(i), Table)
            Return _active
        End Get
    End Property

    Default Public ReadOnly Property Item(ByVal tableName As String) As Table
        Get
            For i As Integer = 0 To _tables.Count - 1
                If CType(_tables(i), Table).TableName = tableName Then
                    _active = CType(_tables(i), Table)
                    Return _active
                End If
            Next
            _active = Nothing
            Return Nothing
        End Get
    End Property

    Public Sub SetNoActiveTable()
        _active = Nothing
    End Sub

    Public ReadOnly Property ActiveTable() As Table
        Get
            Return _active
        End Get
    End Property

    Public ReadOnly Property Count() As Integer
        Get
            Return _tables.Count
        End Get
    End Property

    Public Overrides Function ToString() As String
        Dim out As String = ""
        For i As Integer = 0 To Me.Count - 1
            out = out & Me(i).ToString() & vbCrLf
        Next
        Return out
    End Function
End Class
